#ifndef TINYNDARRAY_INTERNAL_BROADCAST_H
#define TINYNDARRAY_INTERNAL_BROADCAST_H
#include <functional>
#include <sstream>
#include <type_traits>
#include <vector>

#include "misc.h"
#include "tinyndarray.h"

namespace tinyndarray {
Shape PadShape(const Shape& shape, size_t size);
size_t ReduceShapesBroadcast(Shape& ret_shape, Shape& l_shape, Shape& r_shape, const size_t depth_offset);
Shape CheckBroadcastable(const Shape& l_shape, const Shape& r_shape);

// 广播操作的实现
void ApplyOpBroadcastImpl(char* ret_data, const char* l_data, const char* r_data, const Shape& ret_shape,
                          const int ret_size, const std::vector<int>& l_steps, const std::vector<int>& r_steps,
                          const size_t start_depth, const size_t n_depth, const int ret_step, BinaryElementOp op_func,
                          Dtype dtype, size_t type_size);
// 广播操作的主函数
void ApplyOpBroadcast(NdArray& ret, const NdArray& lhs, const NdArray& rhs, const size_t depth_offset,
                      const int ret_step, BinaryElementOp op_func);
}  // namespace tinyndarray
#endif